<?php
/**
 * 丸子妈妈数据修整
* 取unionID
 */
namespace Tools\Controller;
use Common\Model\EventsModel;
use Common\Model\OtherSystem\jch;
use Common\Model\PointMallModel;
use Common\Model\UserModel;
use Common\Model\UtilsModel;
use Common\Model\WeixinModel;
use Think\Controller;
class KnbController extends Controller {


    public function getUnionId(){
        $oldM=M('old_sign',null,DB_MAIN_CFG);
        do {
            $openids = $oldM->where('unionid=""')->limit(100)->getField('openid', true);

            $result = WeixinModel::batchGetUser($openids);
            if ($result['status'] != 0) {
                return;
            }
            foreach ($result['data']['user_info_list'] as $one) {
                $oldM->where("openid='{$one['openid']}'")->save(array('unionid' => $one['unionid']));
            }
        }while(count($openids)>0);

    }

    public function createUser(){
        $u_user_baseM=M('u_user_base',null,DB_MAIN_CFG);
        $u_user_weixinM=M('u_user_weixin',null,DB_MAIN_CFG);
        $oldM=M('old_sign',null,DB_MAIN_CFG);

        do {
            $newUsers = $oldM->where('isnew=1')->limit(100)->select();
            foreach ($newUsers as $one) {
                $newUser = array(
                    'nickname' => $one['nickname'].'',
                    'regTime' => $one['addtime'],
                    'regFrom' => CLIENT_FROM_WX,
                    'sex' => 0,
                );
                $uid = $u_user_baseM->add($newUser);
                $u_user_weixinM->add(array("uid" => $uid, 'WX_unionID' => $one['unionid']));
                $oldM->where("openid='{$one['openid']}'")->setField('isnew', 0);
            }
        }while(count($newUsers)>0);

    }


}




